package com.guoyh.baseutils.ext
import android.content.res.ColorStateList
import android.widget.ImageView
import androidx.core.graphics.drawable.DrawableCompat
import com.guoyh.baseutils.mylog.Loger
import java.lang.Exception

/**
 * @CreateDate: 7/14/21 4:42 PM
 * @Author: guoyh
 * @Description: ImageView相关Ext
 */

fun ImageView.setColorForColor(colors: Int) {
    try {
        drawable.mutate()?.let {
            DrawableCompat.wrap(it)?.apply {
                val colorStateList = ColorStateList.valueOf(colors)
                DrawableCompat.setTintList(this, colorStateList)
                setImageDrawable(this)
            }
        }
    } catch (e: Exception) {

        Loger.dd(e.message)
    }
}


fun ImageView.setColors(colors: String) {
    setColorForColor(getColorm(colors))
    "".toast()
}

fun setImgsColor(color:Int,vararg imgView: ImageView){
    imgView.forEach {img ->
        try {
            img.drawable.mutate()?.let {
                DrawableCompat.wrap(it)?.apply {
                    val colorStateList = ColorStateList.valueOf(color)
                    DrawableCompat.setTintList(this, colorStateList)
                    img.setImageDrawable(this)
                }
            }
        } catch (e: Exception) {
            Loger.dd(e.message)
        }
    }
}
